package com.test.dababy.dababy_00_analytics.DababyUtil

import android.app.Application
import com.facebook.FacebookSdk
import com.facebook.appevents.AppEventsLogger
import com.test.dababy.dababy_00_analytics.dababydata_sdk.dababyutil.DababyASStoreUtil
import com.test.dababy.dababy_01_launcher.Base_dababyApplication
import java.math.BigDecimal
import java.math.RoundingMode

object DababyFacebookUtil {

    /**
     * 初始化facebook模块
     *
     * @param context Application
     */
    fun init_dababy(context: Application) {
        try {
            FacebookSdk.sdkInitialize(context)
            AppEventsLogger.activateApp(context)
        } catch (e: java.lang.Exception) {
            e.printStackTrace()
        }
    }

    /**
     * 保存facebook s2s信息
     */
    fun saveS2SInfo_dababy(targetUrlList: List<String>) {
//        val params = ParamFacebookS2S()
//        val body = Gson().toJson(params).trim()
//        val resultTargetUrlList = TimeZoneUtil.covertToRealTargetServers(targetUrlList)
//        println("====== $resultTargetUrlList")
//
//        //传多国时，里触发多次
//        resultTargetUrlList.forEach { path ->
//            val pathFormat =
//                if (path.endsWith(Url.PATH_FIREBASE_S2S)) path else (path + Url.PATH_FIREBASE_S2S)
//            HttpHelper.postData(pathFormat, body)
//        }
    }

    /**
     * 获取总存储大小
     */
    fun getTotalRom_dababy(): String {
        var totalRom = DababyASStoreUtil.getCashTotal_dababy(Base_dababyApplication.getInstant())
        if (totalRom.endsWith("TB")) {
            totalRom = totalRom.replace("TB".toRegex(), "")
            totalRom =
                BigDecimal(totalRom).multiply(BigDecimal(1024)).stripTrailingZeros().toPlainString()
        } else if (totalRom.endsWith("GB")) {
            totalRom = totalRom.replace("GB".toRegex(), "")
        } else if (totalRom.endsWith("MB")) {
            totalRom = totalRom.replace("MB".toRegex(), "")
            totalRom = BigDecimal(totalRom).divide(BigDecimal(1024), RoundingMode.HALF_UP)
                .stripTrailingZeros().toPlainString()
        }
        return totalRom
    }

    /**
     * 获取可用存储大小
     */
    fun getAvalidableRom_dababy(): String {
        var totalRom =
            DababyASStoreUtil.getCashCanUse_dababy(Base_dababyApplication.getInstant())
        if (totalRom.endsWith("TB")) {
            totalRom = totalRom.replace("TB".toRegex(), "")
            totalRom =
                BigDecimal(totalRom).multiply(BigDecimal(1024)).stripTrailingZeros().toPlainString()
        } else if (totalRom.endsWith("GB")) {
            totalRom = totalRom.replace("GB".toRegex(), "")
        } else if (totalRom.endsWith("MB")) {
            totalRom = totalRom.replace("MB".toRegex(), "")
            totalRom = BigDecimal(totalRom).divide(BigDecimal(1024), RoundingMode.HALF_UP)
                .stripTrailingZeros().toPlainString()
        }
        return totalRom
    }


}